<?php
/** 
 * 举报的操作
 * @author Legend. <xcx_legender@qq.com>
 * @param 
 * @return 
 */

namespace Api\Event;

class AccuseEvent extends BaseEvent 
{	

	/**
	*Mongo集合的实例化
	*/
	protected $serviceObj = '';
	/**
	*参数初始化
	*/
	protected function _initialize(){
		parent::_initialize();
		$this->serviceObj = D('Common/Accuse', 'Service');
	}


	/** 
	 * 对评论进行举报
	 * @author Legend. <xcx_legender@qq.com>
	 * @param 
	 * @return 
	 */
	
	public function comments($uid, $target_id, $type)
	{
		$cService = D('Common/Comments', 'Service');
		$map['id'] = intval($target_id);
		$map['status'] = array('egt', 0);
		if (!$cService->where($map)->count())
		{
			return false;
		}
		return $this->add('comments', $uid, $target_id, $type);
	}

	// 对用户进行举报
	public function user($uid, $target_id, $type)
	{
		return $this->add('user', $uid, $target_id, $type);
	}

	public function video($uid, $target_id, $type)
	{
		return $this->add('video', $uid, $target_id, $type);
	}

	/** 
	 * 主处理方法 不能直接调用 请使用分处理方法
	 * @author Legend. <xcx_legender@qq.com>
	 * @param $module 举报的模型, $uid 举报用户id, $target_id 举报的对象ID, $type 举报类型
	 * @return 
	 */
	
	protected function add($module = 'comments', $uid, $target_id, $type)
	{
		$save['module'] 	= $module;
		$save['uid']		= intval($uid);
		$save['target_id'] 	= intval($target_id);
		
		// 只能对同一个对象发起一次举报   
		if ($this->serviceObj->where($save)->count())
		{
			$this->error = '只能对同一个对象发起一次举报';
			return;
		}
		$save['type'] = intval($type);
		$save = $this->serviceObj->create($save);
		return $save && $this->serviceObj->add($save);
	}


}